// 发帖工具类
import {UrlUtils} from "@/assets/js/UrlUtils";
import {PostAction} from "@ginstone/nga-api/dist/src/enums/PostAction";
import {PrepareModify, PrepareNew, PrepareQuote, PrepareReply} from "@ginstone/nga-api/dist/src/params/PostParams";

const api = "https://bbs.nga.cn/post.php"

export class PostUtils {

    /**
     * 根据操作类型生成请求需要的参数对象
     * @param action 操作类型 {@link PostAction}
     * @param params 参数
     */
    static buildPrepareParams(action, params) {
        const {fid, stid, tid, pid, comment} = params
        switch (action) {
            case PostAction.NEW:
                return new PrepareNew(fid, stid);
            case PostAction.QUOTE:
                return new PrepareQuote(tid, pid);
            case PostAction.REPLY:
                return new PrepareReply(tid, pid, comment);
            case PostAction.MODIFY:
                return new PrepareModify(tid, pid);
            default:
                throw "非法的操作类型: " + action;
        }
    }

    /**
     * 根据参数生成官方网址
     * @param name 路由名称
     * @param params 参数
     * @returns {string}
     */
    static buildOfficialUrl(name, params) {
        return UrlUtils.getUrlByParam(api, {...this.buildPrepareParams(name, params)});
    }
}